import { action, observable } from 'mobx';
import Base from './base';
import isSuccess from '../utils/error';
import userServer from '../services/user';
import { netCheckFn } from '../utils/netCheck';

const { getUserInfo } = userServer;

export default class UserState extends Base {

    @observable info = {};
    @observable loaded = false;

    @action.bound
    async getUserInfo() {
        this.loaded = false;
        // const res = await getUserInfo();
        let res = await netCheckFn('userInfo',async ()=>{
            const res = await getUserInfo();
            return res;
        })
        if (isSuccess(res)) {
            console.log('---UserState getUserInfo---', res);
            window.localStorage.setItem('realname', res.data.realname);
            this.info = res.data;
            this.loaded = true;
        }
    }

}
